

<!DOCTYPE html>
<html class="writer-html5" lang="en" data-content_root="../">
<head>
  <meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" />

  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Tests &mdash; IVRE  documentation</title>
      <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=80d5e7a1" />
      <link rel="stylesheet" type="text/css" href="../_static/css/theme.css?v=e59714d7" />
      <link rel="stylesheet" type="text/css" href="../_static/graphviz.css?v=4ae1632d" />

  
      <script src="../_static/jquery.js?v=5d32c60e"></script>
      <script src="../_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
      <script src="../_static/documentation_options.js?v=5929fcd5"></script>
      <script src="../_static/doctools.js?v=9bcbadda"></script>
      <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
    <script src="../_static/js/theme.js"></script>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="Code linting" href="linting.html" />
    <link rel="prev" title="Web API" href="web-api.html" /> 
</head>

<body class="wy-body-for-nav"> 
  <div class="wy-grid-for-nav">
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >

          
          
          <a href="../index.html" class="icon icon-home">
            IVRE
              <img src="../_static/logo.png" class="logo" alt="Logo"/>
          </a>
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" aria-label="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>
        </div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
              <ul>
<li class="toctree-l1"><a class="reference internal" href="../overview/index.html">Overview</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../install/index.html">Installation</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../usage/index.html">Usage</a></li>
</ul>
<ul class="current">
<li class="toctree-l1 current"><a class="reference internal" href="index.html">Development</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="web-api.html">Web API</a></li>
<li class="toctree-l2 current"><a class="current reference internal" href="#">Tests</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#dependencies">Dependencies</a></li>
<li class="toctree-l3"><a class="reference internal" href="#test-case">Test case</a></li>
<li class="toctree-l3"><a class="reference internal" href="#first-run">First run</a></li>
<li class="toctree-l3"><a class="reference internal" href="#improving-the-test-case">Improving the test case</a></li>
<li class="toctree-l3"><a class="reference internal" href="#failures">Failures</a></li>
<li class="toctree-l3"><a class="reference internal" href="#github-actions">GitHub actions</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="linting.html">Code linting</a></li>
</ul>
</li>
</ul>
<p class="caption" role="heading"><span class="caption-text">Licenses:</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../license.html">IVRE: GPL v3</a></li>
<li class="toctree-l1"><a class="reference internal" href="../license-external.html">Licenses for external files</a></li>
</ul>

        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../index.html">IVRE</a>
      </nav>

      <div class="wy-nav-content">
        <div class="rst-content">
          <div role="navigation" aria-label="Page navigation">
  <ul class="wy-breadcrumbs">
      <li><a href="../index.html" class="icon icon-home" aria-label="Home"></a></li>
          <li class="breadcrumb-item"><a href="index.html">Development</a></li>
      <li class="breadcrumb-item active">Tests</li>
      <li class="wy-breadcrumbs-aside">
            <a href="../_sources/dev/tests.rst.txt" rel="nofollow"> View page source</a>
      </li>
  </ul>
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
             
  <section id="tests">
<h1>Tests<a class="headerlink" href="#tests" title="Link to this heading"></a></h1>
<p>The <code class="docutils literal notranslate"><span class="pre">tests</span></code> directory is mainly intended for people who want to
contribute to IVRE and want to make sure their changes do not break
IVRE.</p>
<section id="dependencies">
<h2>Dependencies<a class="headerlink" href="#dependencies" title="Link to this heading"></a></h2>
<p>To run IVRE tests you will need <a class="reference external" href="http://nedbatchelder.com/code/coverage/">coverage.py</a>.</p>
</section>
<section id="test-case">
<h2>Test case<a class="headerlink" href="#test-case" title="Link to this heading"></a></h2>
<p>The first thing is to find samples. You need both (recent) Nmap XML scan
result files (or Nmap JSON files, as generated by
<code class="docutils literal notranslate"><span class="pre">ivre</span> <span class="pre">scancli</span> <span class="pre">--json</span></code>) and PCAP files (dump while you browse, and
browse a lot, or sniff a busy open Wi-Fi network, if that’s legal in
your country).</p>
<p>A good test case should have a lot of various data (sniff from different
places, scan different hosts with different Nmap options).</p>
<p>It is mandatory to have at least, for the Nmap test:</p>
<ul class="simple">
<li><p>Two scanned (and up) hosts with different IP addresses</p></li>
<li><p>One host scanned with the script <code class="docutils literal notranslate"><span class="pre">http-robots.txt</span></code> reporting
<code class="docutils literal notranslate"><span class="pre">/cgi-bin</span></code> in its output.</p></li>
<li><p>One host scanned with an anonymous FTP server.</p></li>
<li><p>One scan result with traceroute and at least one hop with a hostname.</p></li>
<li><p>One host scanned with a hostname ending with “.com”.</p></li>
</ul>
<p>For the passive test:</p>
<ul class="simple">
<li><p>Two records with different IP addresses.</p></li>
<li><p>One SSL certificate.</p></li>
</ul>
</section>
<section id="first-run">
<h2>First run<a class="headerlink" href="#first-run" title="Link to this heading"></a></h2>
<p>From the <code class="docutils literal notranslate"><span class="pre">tests</span></code> directory, create the <code class="docutils literal notranslate"><span class="pre">samples</span></code> subdirectory and
place your samples there (the PCAP files must have the extension
<code class="docutils literal notranslate"><span class="pre">.pcap</span></code>, the Nmap XML result files must have the extension <code class="docutils literal notranslate"><span class="pre">.xml</span></code>,
and the Nmap JSON results must have the extension <code class="docutils literal notranslate"><span class="pre">.json</span></code>).</p>
<p>Then, run <code class="docutils literal notranslate"><span class="pre">python</span> <span class="pre">./tests.py</span></code> (optionally replace <code class="docutils literal notranslate"><span class="pre">python</span></code> by the
alternative interpreter you want to use, e.g., <code class="docutils literal notranslate"><span class="pre">python3.12</span></code>; note
that <code class="docutils literal notranslate"><span class="pre">coverage.py</span></code> must be installed for this interpreter).  The
first run will create a <code class="docutils literal notranslate"><span class="pre">samples/results</span></code> file with the expected
values for some results. The next runs will use those values to check
if something has been broken.</p>
<p>For this reason, it is important to:</p>
<ul class="simple">
<li><p>Run the tests for the first time with a “known-working” version.</p></li>
<li><p>Remove the file <code class="docutils literal notranslate"><span class="pre">samples/results</span></code> whenever a sample file is added,
modified or removed.</p></li>
</ul>
</section>
<section id="improving-the-test-case">
<h2>Improving the test case<a class="headerlink" href="#improving-the-test-case" title="Link to this heading"></a></h2>
<p>If you want to make sure to have enough samples, you can:</p>
<ul class="simple">
<li><p>Check the <code class="docutils literal notranslate"><span class="pre">samples/results</span></code> file for <code class="docutils literal notranslate"><span class="pre">*_count</span></code> entries with low
values (particularly 0, of course) and find or create new samples
that will improve those values.</p></li>
<li><p>Check the report generated by coverage.py under the <code class="docutils literal notranslate"><span class="pre">htmlcov</span></code>
directory, and check whether your current test case covers at least
the code you want to change.</p></li>
</ul>
</section>
<section id="failures">
<h2>Failures<a class="headerlink" href="#failures" title="Link to this heading"></a></h2>
<p>Tests failure are not always an issue. Apart from a new bug, of course,
here are some reasons that can explain test failures:</p>
<ul class="simple">
<li><p>You have added new samples and have not removed the
<code class="docutils literal notranslate"><span class="pre">samples/results</span></code> file.</p></li>
<li><p>Your samples do not match the minimum requirements detailed above.</p></li>
<li><p>A new feature has been added to IVRE and the new results are actually
better than the stored ones.</p></li>
</ul>
</section>
<section id="github-actions">
<h2>GitHub actions<a class="headerlink" href="#github-actions" title="Link to this heading"></a></h2>
<p>Tests are run with several MongoDB and PostgreSQL versions, as well as
TinyDB, SQLite and Elasticsearch for each pull requests. The tests run
with Python 3.11 to 3.12.</p>
<p>The configurations are in the <cite>.github/workflows/*.yml</cite> YAML files.</p>
</section>
</section>


           </div>
          </div>
          <footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer">
        <a href="web-api.html" class="btn btn-neutral float-left" title="Web API" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
        <a href="linting.html" class="btn btn-neutral float-right" title="Code linting" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
    </div>

  <hr/>

  <div role="contentinfo">
    <p>&#169; Copyright 2011 - 2025, Pierre LALET.</p>
  </div>

  Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
    <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
    provided by <a href="https://readthedocs.org">Read the Docs</a>.
   

</footer>
        </div>
      </div>
    </section>
  </div>
  <script>
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script> 

</body>
</html>